<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>商品信息</title>
    <link href="${pageContext.request.contextPath}/admin/css/style.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.js"></script>
    <script language="javascript" type="text/javascript"
            src="${pageContext.request.contextPath}/admin/js/My97DatePicker/WdatePicker.js"></script>

    <script>
        // old write
        $(document).ready(function () {
            $(".click").click(function () {
                $(".tip").fadeIn(200);
            });

            $(".tiptop a").click(function () {
                $(".tip").fadeOut(200);
            });

            $(".sure").click(function () {
                $(".tip").fadeOut(100);
            });

            $(".cancel").click(function () {
                $(".tip").fadeOut(100);
            });
        });

        function checkAll() {
            var alls = document.getElementsByName("id");
            var ch = document.getElementById("allIds");
            if (ch.checked) {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = true;
                }
            } else {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = false;
                }
            }
        }

        function deleteBys() {
            var alls = document.getElementsByName("id");
            var ids = new Array();
            for (var i = 0; i < alls.length; i++) {
                if (alls[i].checked) {
                    ids.push(alls[i].value);
                }
            }
            if (ids.length > 0) {
                if (confirm("确认操作?")) {
                    // alert(ids);
                    var id = ids + "";
                    deleteBy(id);
                }
            } else {
                alert("请选中要操作的项");
            }
        }

        function deleteBy(id) {
            $.ajax({
                "url": "${pageContext.request.contextPath}/productServlet",
                "type": "post",
                "data": {"mark": "deleteProduct", "id": id},
                "dataType": "text",
                "success": function (data) {
                    if (data == "true") {
                        alert("删除成功");
                        window.location.href = "${pageContext.request.contextPath}/productServlet?mark=showProduct";
                    } else {
                        alert("删除失败");
                    }
                },
                "error": function () {
                    alert("删除请求失败");
                }
            });
        }

        function addProduct() {
            window.location.href="${pageContext.request.contextPath}/productServlet?mark=goAddProduct";
        }

    </script>
</head>
<body>

<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">商品管理</a></li>
    </ul>
</div>

<div class="rightinfo">
    <div class="tools">
        <ul class="toolbar">
            <li style="cursor: pointer;" id="addProduct" onclick="addProduct()"><span>
                <img src="${pageContext.request.contextPath}/admin/images/t01.png"/>
            </span>添加商品
            </li>
            <li style="cursor: pointer;" onclick="deleteBys()"><span>
                <img src="${pageContext.request.contextPath}/admin/images/t03.png"/>
            </span>批量删除
            </li>
        </ul>
        <form id="f5" action="${pageContext.request.contextPath}/productServlet?mark=showProduct" method="post">
            <div style="width: 90%;height: 30px; text-align: center;">
                商品名称：<input name="pname" style="height: 25px;border:1px solid #ccc;" type="text" placeholder="商品名称"
                            value=""/> &nbsp;&nbsp;
                <!-- 0 正常,1热门产品，2为你推荐，3，新品 4，小米明星单品 -->

                是否热推：
                <select name="state" style="height: 28px;border:1px solid #ccc;">
                    <option value="">=== 请选择 ===</option>
                    <option value="0">普通商品</option>
                    <option value="1">热门产品</option>
                    <option value="2">为你推荐</option>
                    <option value="3">新品</option>
                    <option value="4">小米明星单品</option>
                </select> &nbsp;&nbsp;
                时间：<input class="Wdate" name="start_time" type="text" style="height: 25px;border:1px solid #ccc;"
                          onclick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})"/> ~
                <input class="Wdate" name="end_time" type="text" style="height: 25px;border:1px solid #ccc;"
                       onclick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>&nbsp;&nbsp;
                <input type="submit" value="查询" style="width: 60px;height: 30px;"/>
            </div>
            <br/>
        </form>
    </div>


    <table class="tablelist">
        <thead>
        <tr>
            <th><input id="allIds" type="checkbox"  onchange="checkAll()"/></th>
            <th>序号<i class="sort"><img src="${pageContext.request.contextPath}/admin/images/px.gif"/></i></th>
            <th>商品类别</th>
            <th>商品名称</th>
<%--            <th>尺寸</th>--%>
            <th>商品颜色</th>
            <th>商品价格</th>
            <th width="18%">简介</th>
            <th width="40">商品图</th>
            <th>是否热推</th>
            <th>型号</th>
            <th>生产日期</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${selectProductPages}" var="product">
            <tr>
                <td><input name="id" type="checkbox" value="${product.pid}"/></td>
                <td>${product.pid}</td>
                <td>${product.cname}</td>
                <td>${product.name}</td>
<%--                <td>${product.size}</td>--%>
                <td>${product.color}</td>
                <td>${product.price}</td>
                <td width="18%" title="${product.full_description}" style="cursor: pointer;">${product.description}</td>
                <td>
                    <img src="${pageContext.request.contextPath}/file/${product.pic}" alt="" width="40" height="40"/>
                </td>
                <td>
                    <!-- 0 正常,1热门产品，2为你推荐，3，新品 4，小米明星单品 -->
                    <c:if test="${product.state==0}">正常</c:if>
                    <c:if test="${product.state==1}">热门产品</c:if>
                    <c:if test="${product.state==2}">为你推荐</c:if>
                    <c:if test="${product.state==3}">新品</c:if>
                    <c:if test="${product.state==4}">小米明星单品</c:if>
                </td>
                <td>${product.version}</td>
                <td><fmt:formatDate pattern="yyyy-mm-dd hh-mm-ss" value="${product.product_date}"></fmt:formatDate></td>
                <td>
                    <a href="javascript:void(0)" onclick="deleteBy('${product.pid}')">删除</a>&nbsp;&nbsp;
                    <a href="${pageContext.request.contextPath}/productServlet?mark=showUpdateProduct&pid=${product.pid}">修改${msg}</a>
                </td>
            </tr>
        </c:forEach>

        </tbody>
    </table>

    <div class="pagin">
        <div class="message">共找到<i class="blue">${pageUtils.totalPageCount}</i>条记录，当前显示第&nbsp;<i
                class="blue">${pageUtils.currentPage}&nbsp;/&nbsp;${pageUtils.totalPageSize}</i>页
        </div>
        <ul class="paginList">

            <li class="paginItem"><a
                    href="${pageContext.request.contextPath}/productServlet?mark=showProduct&currenPage=1&pname=${name}&state=${state}&start_time=${startTime}&end_time=${endTime}">首页</a>
            </li>
            <c:if test="${pageUtils.currentPage>1}">
                <li class="paginItem"><a
                        href="${pageContext.request.contextPath}/productServlet?mark=showProduct&currentPage=${pageUtils.currentPage-1}&pname=${name}&state=${state}&start_time=${startTime}&end_time=${endTime}">上一页</a>
                </li>
            </c:if>
            <c:if test="${pageUtils.currentPage<=1}">
                <li class="paginItem"><a href="javascript:void(0);" style="opacity: 0.5;cursor: default;"
                                         title="已经是第一页了" class="paginItemNone">上一页</a></li>
            </c:if>
            <%--            <li class="paginItem">--%>
            <%--                <a>--%>
            <%--                    <form action="${pageContext.request.contextPath}/productServlet?mark=showProduct">--%>
            <%--                        <input type="number" name="pageSize" placeholder="${pageUtils.pageSize}" value="pageSize" min="1" max="${pageUtils.totalPageCount}" style="width: 100%;height: 100%;text-align: center;"/>--%>
            <%--                        <input type="submit" hidden>--%>
            <%--                    </form>--%>
            <%--                </a>--%>
            <%--            </li>--%>
            <c:if test="${pageUtils.currentPage < pageUtils.totalPageSize}">
                <li class="paginItem"><a
                        href="${pageContext.request.contextPath}/productServlet?mark=showProduct&currentPage=${pageUtils.currentPage+1}&pname=${name}&state=${state}&start_time=${startTime}&end_time=${endTime}">下一页</a>
                </li>
            </c:if>
            <c:if test="${pageUtils.currentPage >= pageUtils.totalPageSize}">
                <li class="paginItem"><a href="javascript:void(0);" style="opacity: 0.5 ;cursor: default; "
                                         title="没有更多了">下一页</a></li>
            </c:if>
            <li class="paginItem"><a
                    href="${pageContext.request.contextPath}/productServlet?mark=showProduct&currentPage=${pageUtils.totalPageSize}&pname=${name}&state=${state}&start_time=${startTime}&end_time=${endTime}">尾页</a>
            </li>
        </ul>
    </div>

    <div class="tip">
        <div class="tiptop"><span>提示信息</span><a></a></div>

        <div class="tipinfo">
            <span><img src="images/ticon.png"/></span>
            <div class="tipright">
                <p>是否确认对信息的修改 ？</p>
                <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
            </div>
        </div>

        <div class="tipbtn">
            <input name="" type="button" class="sure" value="确定"/>&nbsp;
            <input name="" type="button" class="cancel" value="取消"/>
        </div>
    </div>
</div>

<script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
